package com.ying.routing;

import com.rabbitmq.client.*;
import com.ying.util.RabbitMQUtils;

import java.io.IOException;

/**
 * ClassName: pubsubConsumer01
 * Package: com.ying.pubsub
 * Description:
 *
 * @Author 刘英杰
 * @Create 2025/3/27 14:35
 * @Version 1.0
 */
public class RoutingConsumer02 {
    public static void main(String[] args) throws IOException {
        Connection connection = RabbitMQUtils.getConnection("192.168.160.134", 5672, "myHV",
                "testUser", "123456");

        Channel channel = connection.createChannel();

        channel.queueDeclare("directQueue2",true,false,false,null);

        channel.basicConsume("directQueue2",true,new DefaultConsumer(channel){
            /**
             *
             consumerTag – 与消费者相关联的唯一标识
             envelope – 获取交换机信息,routing key等信息
             properties –  获取信息相关的属性,AMQP.BasicProperties
             body – 消息内容
             */
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println(new String(body));
            }
        });
    }
}
